<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>登录</title>
		<link rel="stylesheet" href="${BASE_PATH}/static/app/css/base.css" />
		<link rel="stylesheet" type="text/css" href="${BASE_PATH}/static/app/css/header.css"/>
		<link rel="stylesheet" href="${BASE_PATH}/static/app/css/public.css" />
		<link rel="stylesheet" href="${BASE_PATH}/static/app/css/changePassword.css" />
		<style>
			.ok{
				margin-top: 60px;
			}
	
			.tip{
			    font-size: 12px;
			    padding-left: 1rem;
			    padding-top: .5rem;
			    color: #bbbcb7;
			}

		</style>
	</head>
	<body>
		<div class="header_order">
			<span class="back" onclick="javascript:history.go(-1);"></span>
			<span class="header_text">登录</span>
		</div>
		<div class="tel_num line">
			<span>手机号</span>
			<input type="text" id="phoneInpt" placeholder="请输入手机号码" />
			<span id="sendCode" class="get_code" onclick="doSendCode()">获取验证码</span>
			<span id="sendedCode" class="wite_code" style="display: none;">获取验证码</span>
		</div>
		<div class="code line">
			<span>验证码</span>
			<input type="text" id="codeInpt" placeholder="请输入验证码"/>
		</div>
		<p class="tip">温馨提示：未注册的用户，登录时将自动注册为会员</p>
		 <input type="text" hidden="hidden" id="sid" value=${sid}>
		<div class="ok" onclick="doRegist();">确定</div>
		<script type="text/javascript" src="${BASE_PATH}/static/app/js/jquery-3.1.1.min.js"></script>
		<script type="text/javascript" src="${BASE_PATH}/static/lib/layer/layer.js"></script>
		<script type="text/javascript" src="${BASE_PATH}/static/app/js/kit.js"></script>
		<script type="text/javascript">
			var counterNum = 60,counter;
			function doSendCode(){
				var phone = $("#phoneInpt").val();
				Kit.ajax.post("${BASE_PATH}/sendRegCode",{phone:phone},function(result){
					if(result.flag==1){
						Kit.ui.alert("手机号不能为空！");
					}else if(result.flag==0){
						Kit.ui.toast("发送成功！");
						Kit.ui.toggle("#sendedCode","#sendCode");
						counter = setInterval(function(){
							if(counterNum>0){
								$("#sendedCode").html((counterNum--)+"秒后获取");
							}else{
								clearInterval(counter);
								counterNum = 60;
								Kit.ui.toggle("#sendCode","#sendedCode");
							}
						}, 1000);
					}
				});
			}
			function doRegist(){
				var phone = $("#phoneInpt").val();
				var code = $("#codeInpt").val();
				var sid=$("#sid").val();
				Kit.ajax.post("${BASE_PATH}/doRegist",{phone:phone,code:code},function(result){
					if(result.flag==1){
						Kit.ui.alert("手机号不能为空！");
					}else if(result.flag==2){
						Kit.ui.alert("手机号不正确！");
					}else if(result.flag==3){
						setTimeout(function(){
							Kit.render.redirect("${BASE_PATH}/dologin/"+phone);
						}, 1000);
					}else if(result.flag==7){
						Kit.ui.alert("验证码不能为空！");
					}else if(result.flag==8){
						Kit.ui.alert("请重新获取验证码！");
					}else if(result.flag==9){
						Kit.ui.alert("验证码错误！");
					}else if(result.flag==0){
						setTimeout(function(){
							Kit.render.redirect("${BASE_PATH}/info?phone="+phone);
						}, 1000);
					}
				});
			}
		</script>
	</body>
</html>